<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>节点列表</title>
    <link rel="shortcut icon" href="__STATIC__/admin/images/favicon.ico">
    <link href="__STATIC__/admin/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/font-awesome.min.css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/font-awesome-ie7.min.css"/>
    <![endif]-->
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace-rtl.min.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace-skins.min.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/css/style.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/css/node.css"/>
    <script src="__STATIC__/admin/js/jquery-1.9.1.min.js"></script>
    <script src="__STATIC__/admin/assets/layer/layer.js" type="text/javascript"></script>
</head>

<body>
<div class="crumbs">
    <ul>
        <li>
            <a href="javascript:;" class="active">权限管理</a>
        </li>
    </ul>
</div>
<div id="wrap">
    <a href="javascrript:;">为【{$role.remark}】分配权限</a>
    <div class="app">
        <form action="{:url('rbac/access')}" method="post">
            <input type="hidden" name="id" value="{$role.id}">
            <div>
                <input type="submit" class="btn btn-primary" value="提交">
            </div>
            {foreach $rules as $rule}
            <dl>
                <dt>
                    <input type="checkbox" value="{$rule.id}" name="rule[]" class="controller_rule"
                    {if condition="in_array($rule.id,$has_rules_one)"}checked{/if}
                    >
                    <strong>{$rule.title}</strong>
                </dt>
                {foreach $rule.child as $item}
                <dd>
                    <input type="checkbox" value="{$item.id}" name="rule[]" class="action_rule"
                           {if condition="in_array($item.id,$has_rules_one)"}checked{/if}>
                    <span>{$item.title}</span>
                </dd>
                {/foreach}
            </dl>
            {/foreach}
        </form>
    </div>
</div>

</body>

</html>
<script>
    $('.action_rule').on('click', function () {
        //操作复选框的 checked 属性要使用 prop 方法
        if ($(this).prop('checked')) {
            $(this).parent().parent().find('.controller_rule').prop('checked', true);
        }
    })
    $('.controller_rule').on('click', function () {
        if ($(this).prop('checked') == false) {
            $(this).parent().parent().find('.action_rule').prop('checked', false);
        }
    })
</script>
